﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XT.Model;
using XT.Repository;

namespace XT.BusinessService
{
    
    public class AreaService : IAreaService
    {
        private readonly IUow _uow;
        public AreaService(IUow uow)
        {
            _uow = uow;
        }


        public IEnumerable<Area> GetArea()
        {
            return _uow.AreaRepo.FindAll<Area>(o => o.OrderByDescending(c => c.Id));
            
        }

        public Area searchAreaByName(string txt)
        {
            return _uow.AreaRepo.ExecuteQuery(context => context.GetTable<Area>().SingleOrDefault(c => c.Area_Name.Equals(txt)));
        }

        public Area GetAreaByID(int id)
        {
            return _uow.AreaRepo.Find(id);
        }

        public IEnumerable<Area> SuggestAreas(string txt)
        {
            return _uow.AreaRepo.FindAllByCriteria<Area>((c => c.Area_Name.ToLower().Contains(txt.ToLower())), o => o.OrderByDescending(c => c.Id));
        }

    }
}
